package com.ht.module.bus.controller;

import com.ht.util.JsonResult;
import com.ht.util.Pager;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ht.module.bus.entity.TClass;
import com.ht.module.bus.service.TClassService;
import com.ht.util.*;
import javax.validation.Valid;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hejialun
 * @since 2024-07-29
 */
@RestController
@RequestMapping("/t-class")
public class TClassController {

    
    @Autowired
    private TClassService tClassService;


	@ApiOperation("按权限分页查询班级")
    @GetMapping("/findPageAuth")
    public JsonResult findPageAuth(Pager<TClass> pager, TClass en){
        return JsonResult.success(tClassService.findPageAuth(pager,en));
    }

    @ApiOperation("按权限查所有班级")
    @GetMapping("/findListAuth")
    public JsonResult findListAuth(TClass en){
        return JsonResult.success(tClassService.findListAuth(en));
    }


    @ApiOperation("分页查询班级")
    @GetMapping("/findPage")
    public JsonResult findPage(Pager<TClass> pager, TClass en){
        return JsonResult.success(tClassService.findPage(pager,en));
    }

    @ApiOperation("查所有班级")
    @GetMapping("/findList")
    public JsonResult findList(TClass en){
        return JsonResult.success(tClassService.findList(en));
    }




    @ApiOperation("通过id查询")
    @GetMapping("/get-by-id/{id}")
    public JsonResult getById(@PathVariable(value = "id") String id){
        return JsonResult.success(tClassService.getById(id));
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    public JsonResult add(@RequestBody @Valid TClass en){
	    CommMethod.beanCreate(en);
        tClassService.add(en);
        return JsonResult.success();
    }

    @ApiOperation("批量添加班级")
    @PostMapping("/addBatch")
    public JsonResult addBatch(@RequestBody @Valid List<TClass> list){
        for (TClass en : list) {
            CommMethod.beanCreate(en);
        }
        tClassService.saveBatch(list);
        return JsonResult.success();
    }

    @ApiOperation("通过id删除")
    @DeleteMapping("/delete-by-id/{id}")
    public JsonResult delete(@PathVariable(value = "id") String id){
        tClassService.removeById(id);
        return JsonResult.success();
    }

    @ApiOperation("修改")
    @PutMapping("/update")
    public JsonResult updateById(@RequestBody @Valid TClass en){
	    CommMethod.beanUpdate(en);
        tClassService.editById(en);
        return JsonResult.success();
    }

}
